import request from './axios';

/**
 * 支付宝支付请求参数
 */
export interface AlipayOrderRequest {
  orderId: number;         // 订单ID
  orderNumber: string;     // 订单号
  totalAmount: number;     // 总金额
  subject: string;         // 订单标题
  body?: string;           // 订单描述
  returnUrl?: string;      // 付款完成后的跳转页面
}

/**
 * 创建支付宝支付订单
 * @param orderData 订单数据
 */
export function createAlipayOrder(orderData: AlipayOrderRequest) {
  return request({
    url: '/payment/alipay/create',
    method: 'post',
    data: orderData
  });
}

/**
 * 查询支付宝支付状态
 * @param orderNumber 订单号
 */
export function checkPaymentStatus(orderNumber: string) {
  return request({
    url: `/payment/status/${orderNumber}`,
    method: 'get'
  });
}

/**
 * 手动关闭支付订单
 * @param orderNumber 订单号
 */
export function closePayment(orderNumber: string) {
  return request({
    url: `/payment/close/${orderNumber}`,
    method: 'post'
  });
}

/**
 * 获取支付记录
 * @param orderNumber 订单号
 */
export function getPaymentRecords(orderNumber: string) {
  return request({
    url: `/payment/records/${orderNumber}`,
    method: 'get'
  });
}

export default {
  createAlipayOrder,
  checkPaymentStatus,
  closePayment,
  getPaymentRecords
}; 